
/**
 * 根据deal_status处理经纪商行情推送过来的数据
 * 如果=-1，不处理该条记录；
 * 如果=0，直接插入改条记录；
 * 如果=1，取出该条记录中的msgID，找到msgID对应的历史记录，如果有的话，更该条记录的数据（除deal_time之外）；
 * 如果=2，取出该条记录中的msgID，找到msgID对应的历史记录，如果有的话，删除该条记录；
 * 报价的一条会分别有买和卖的msgid和deal_status
 * */
 const dealBrokerQuoteListByDealStatus = (
  quoteList,
  quote
) => {
  const { quoteBuyMsgId, quoteBuyDealStatus, quoteSellMsgId, quoteSellDealStatus } = quote
  //如果买卖都是新增
  if (quoteBuyDealStatus === 0 && quoteSellDealStatus === 0) {
    quoteList.push(quote)
  }
  //如果买是新增，卖是删或者更
  if (quoteBuyDealStatus === 0 && quoteSellDealStatus !== 0) {
    quoteList.push({
      quoteMaker: quote.quoteMaker,
      quoteTaker: quote.quoteTaker,
      quoteMakerCode: quote.quoteMakerCode,
      time: quote.time,
      buyQty: quote.buyQty,
      buyPrice: quote.buyPrice,
      buyNetPrice: quote.buyNetPrice,
      buyFullPrice: quote.buyFullPrice,
      buyQtyVolumn: quote.buyQtyVolumn,
      buyQtyDesc: quote.buyQtyDesc,
      sellPrice: '--',
      sellNetPrice: '--',
      sellFullPrice: '--',
      sellQtyVolumn: '--',
      sellQtyDesc: '--',
      sellSettleSpeed: '--',
      sellQty: '--',
      quoteBuyMsgId: quote.quoteBuyMsgId,
      quoteBuyDealStatus: quote.quoteBuyDealStatus,
      isSellEmpty: true,
      isBuyEmpty: false,
    })
  }

  //如果卖是新增，买是删或者更
  if (quoteSellDealStatus === 0 && quoteBuyDealStatus !== 0) {
    quoteList.push({
      quoteMaker: quote.quoteMaker,
      quoteTaker: quote.quoteTaker,
      quoteMakerCode: quote.quoteMakerCode,
      time: quote.time,
      buyPrice: '--',
      buyNetPrice: '--',
      buyFullPrice: '--',
      buyQtyVolumn: '--',
      buyQtyDesc: '--',
      buySettleSpeed: '--',
      buyQty: '--',
      sellPrice: quote.sellPrice,
      sellNetPrice: quote.sellNetPrice,
      sellFullPrice: quote.sellFullPrice,
      sellQtyVolumn: quote.sellQtyVolumn,
      sellQtyDesc: quote.sellQtyDesc,
      sellSettleSpeed: quote.sellSettleSpeed,
      sellQty: quote.sellQty,
      quoteSellMsgId: quote.quoteSellMsgId,
      quoteSellDealStatus: quote.quoteSellDealStatus,
      isSellEmpty: false,
      isBuyEmpty: true,
    })
  }

  //如果买是删或者更
  const quoteBuyIndex = quoteList.findIndex(item => item.quoteBuyMsgId === quoteBuyMsgId)
  if (quoteBuyDealStatus !== 0 && quoteBuyIndex !== -1) {
    //如果买是删除，则需判断quoteBuyIndex对应的数据的卖是不是空，如果是则直接删除，否则只将买的数据清空
    if (quoteBuyDealStatus === -1) {
      if (quoteList[quoteBuyIndex].isSellEmpty) {
        quoteList.splice(quoteBuyIndex, 1)
      } else {
        quoteList[quoteBuyIndex].buyQty = '--'
        quoteList[quoteBuyIndex].buyPrice = '--'
        quoteList[quoteBuyIndex].buyNetPrice = '--'
        quoteList[quoteBuyIndex].buyFullPrice = '--'
        quoteList[quoteBuyIndex].buyQtyVolumn = '--'
        quoteList[quoteBuyIndex].buyQtyDesc = '--'
        quoteList[quoteBuyIndex].buySettleSpeed = '--'
        quoteList[quoteBuyIndex].buyQty = '--'
        quoteList[quoteBuyIndex].isBuyEmpty = true
      }
    } else if (quoteBuyDealStatus === 1) {
      quoteList[quoteBuyIndex].buyQty = quote.buyQty
      quoteList[quoteBuyIndex].buyPrice = quote.buyPrice
      quoteList[quoteBuyIndex].buyNetPrice = quote.buyNetPrice
      quoteList[quoteBuyIndex].buyFullPrice = quote.buyFullPrice
      quoteList[quoteBuyIndex].buyQtyVolumn = quote.buyQtyVolumn
      quoteList[quoteBuyIndex].buyQtyDesc = quote.buyQtyDesc
      quoteList[quoteBuyIndex].buySettleSpeed = quote.buySettleSpeed
      quoteList[quoteBuyIndex].isBuyEmpty = false
    }
  }

  //如果卖是删或者更
  const quoteSellIndex = quoteList.findIndex(item => item.quoteSellMsgId === quoteSellMsgId)
  if (quoteSellDealStatus !== 0 && quoteSellIndex !== -1) {
    //如果卖是删除，则需判断quoteIndex对应的数据的买是不是空，如果是则直接删除，否则只将卖的数据清空
    if (quoteSellDealStatus === -1) {
      if (quoteList[quoteSellIndex].isBuyEmpty) {
        quoteList.splice(quoteSellIndex, 1)
      } else {
        quoteList[quoteSellIndex].sellPrice = '--'
        quoteList[quoteSellIndex].sellNetPrice = '--'
        quoteList[quoteSellIndex].sellFullPrice = '--'
        quoteList[quoteSellIndex].sellQtyVolumn = '--'
        quoteList[quoteSellIndex].sellQtyDesc = '--'
        quoteList[quoteSellIndex].sellSettleSpeed = '--'
        quoteList[quoteSellIndex].sellQty = '--'
        quoteList[quoteSellIndex].isSellEmpty = true
      }
    }
    if (quoteSellDealStatus === 1) {
      quoteList[quoteSellIndex].sellPrice = quote.sellPrice
      quoteList[quoteSellIndex].sellNetPrice = quote.sellNetPrice
      quoteList[quoteSellIndex].sellFullPrice = quote.sellFullPrice
      quoteList[quoteSellIndex].sellQtyVolumn = quote.sellQtyVolumn
      quoteList[quoteSellIndex].sellQtyDesc = quote.sellQtyDesc
      quoteList[quoteSellIndex].sellSettleSpeed = quote.sellSettleSpeed
      quoteList[quoteSellIndex].sellQty = quote.sellQty
      quoteList[quoteSellIndex].isSellEmpty = false
    }
  }
}


const quoteList = [{
  quoteBuyMsgId: '1',
  quoteSellMsgId: '2',
  quoteMaker: '1',
  quoteTaker: '2',
  quoteMakerCode: '1',
  time: '1',
  buyQty: '1',
  buyPrice: '1',
  buyNetPrice: '1',
  buyFullPrice: '1',
  buyQtyVolumn: '1',
  buyQtyDesc: '1',
  sellPrice: '1',
  sellNetPrice: '1',
  sellFullPrice: '1',
  sellQtyVolumn: '1',
  sellQtyDesc: '1',
  sellSettleSpeed: '1',
  sellQty: '1',
  isSellEmpty: false,
  isBuyEmpty: false,
}]

const quote = {
    quoteBuyMsgId: '1',
    quoteBuyDealStatus: -1,
    quoteSellMsgId: '22',
    quoteSellDealStatus: -1,
    quoteMaker: '1',
    quoteTaker: '2',
    quoteMakerCode: '1',
    time: '1',
    buyQty: 'new',
    buyPrice: 'new',
    buyNetPrice: 'new',
    buyFullPrice: 'new',
    buyQtyVolumn: 'new',
    buyQtyDesc: 'new',
    sellPrice: 'new',
    sellNetPrice: 'new',
    sellFullPrice: 'new',
    sellQtyVolumn: 'new',
    sellQtyDesc: 'new',
    sellSettleSpeed: 'new',
    sellQty: 'new',
    isSellEmpty: false,
    isBuyEmpty: false,
}

dealBrokerQuoteListByDealStatus(quoteList, quote)
console.log(quoteList)